import axios from "axios";

const Console = () => {
  const onClick = () => {
    // 直接请求目标服务，会跨域
    let url =
      "https://i.maoyan.com/api/mmdb/movie/v3/list/hot.json?ct=%E6%B7%B1%E5%9C%B3&ci=30&channelId=4";

    // 请求中间层的自己的后端服务 8080
    url =
      "http://localhost:8080/maoyan/api/mmdb/movie/v3/list/hot.json?ct=%E6%B7%B1%E5%9C%B3&ci=30&channelId=4";

    // 该项目中配置了开发代理（setupProxy.js）这时请求地址,将原目标地址中的域名修改为当前前端项目的域名
    // url =
    //   "http://localhost:3000/maoyan/api/mmdb/movie/v3/list/hot.json?ct=%E6%B7%B1%E5%9C%B3&ci=30&channelId=4";

    axios.get(url).then((res) => {
      console.log(res);
    });
  };

  return (
    <div>
      <h1>Console</h1>
      <button onClick={onClick}>点我调用猫眼电影</button>
    </div>
  );
};

export default Console;
